Skip to content

Add Phone PWA, QR-code pairing, and VAPID Web Push notifications - #382

Merged
d41sys merged 1 commit into
mainfrom
issue-375-pwa-qr-push
Dec 4, 2026
Merged

d41sys merged 1 commit into
mainfrom
issue-375-pwa-qr-push

Conversation

@d41sys

@d41sys d41sys commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Summary

Makes Bate's embedded device page feel like a companion phone app with QR-code pairing, installable PWA metadata, and encrypted Web Push notifications — with zero new dependencies:

  1. QR-code pairing (proto/src/qr.rs, appd/src/lan.rs, window/ui/src/Devices.tsx, native/src/settings_devices.rs):
    • Adds a pure-Rust ISO/IEC 18004 QR encoder (proto::qr::encode, Byte mode, EC Level M, versions 1–10) producing both compact row matrices and crisp SVG paths with a 4-module quiet zone.
    • pair_device now includes url (https://<host>:<port>/?pair=<code>) and qr ({size, rows}) when a network address is available.
    • Renders the vector QR code beside the pairing code in Settings → Other devices in both native (visually verified in light/dark snapshots) and window/ui.
    • Pair in window/ui/src/Devices.tsx pre-fills the code from ?pair=<code> and strips it from browser history.
  2. Installable PWA (window/ui/index.html, window/ui/public/{manifest.webmanifest,icon.svg,sw.js}, window/ui/src/style.css, appd/src/lan.rs):
    • Adds standalone Web App Manifest, mobile viewport (viewport-fit=cover) + safe-area inset rules, SVG icon, and minimal Service Worker (push + notificationclick), served over LAN/Tailscale HTTPS with proper MIME types and Service-Worker-Allowed: /.
  3. Web Push (VAPID) notifications (appd/src/push.rs, appd/src/lan.rs, appd/src/core.rs, window/ui/src/service.ts):
    • Generates and stores a P-256 VAPID keypair exclusively in macOS Keychain (vapid.key, never in logs, frames, or app.db), encrypting payloads with RFC 8291 (aes128gcm) and signing requests with RFC 8292 ES256 JWTs using ring.
    • Adds paired-device-authenticated /api/push/key, /api/push/subscribe, and /api/push/unsubscribe endpoints; removing a Device clears its subscriptions and expired 404/410 subscriptions are pruned automatically.
    • Dispatches push notifications on a background thread when a bot asks a question (Needs you) or finishes a Routine, strictly redacting Secret prompts so bot text and secret names never appear in push payloads.

Closes #375.

Evidence

  • cd window/ui && npm ci && npm run build && npm test: passed (142/142 tests, including style.test.ts and standin.test.mjs).
  • cargo fmt --all --check: passed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed.
  • cargo test --workspace --locked --no-fail-fast: passed across all crates, including:
    • proto::qr::tests::encodes_pairing_urls_deterministically_with_valid_finders_and_svg
    • appd::push::tests::{base64url_round_trips, secret_prompt_payload_redacts_bot_text_and_secret_names, vapid_jwt_and_rfc8291_encryption_produce_valid_frames, subscription_validation_rejects_non_https_and_bad_keys}
    • appd/tests/service.rs::pwa_manifest_qr_pairing_and_web_push_subscription_lifecycle
    • native/tests/settings.rs (44/44 passed, asserting pair-qr renders and visually verifying updated native-settings-pairing-{light,dark}.png).

Merge Danger

Low. Adds optional url/qr fields to pair_device, static PWA files, and paired-device-only /api/push/* routes. No existing socket command or schema changes; Web Push stays inactive until a paired Device subscribes.

Device decision

  • No new service-socket commands added (ALLOWED_OVER_LAN / REFUSED_OVER_LAN unchanged).
  • pair_device remains refused from paired Devices; /api/push/{key,subscribe,unsubscribe} require a valid paired Device cookie plus x-bate: 1, and a Device can only manage its own subscriptions.

@d41sys
d41sys merged commit 7b1c3a3 into main Dec 4, 2026
5 checks passed
@d41sys
d41sys deleted the issue-375-pwa-qr-push branch December 4, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phone PWA, QR-code pairing, and Web Push (VAPID) notifications for paired Devices

1 participant